package com.huawei.appmarket.service.store.awk.card;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.horizontalcard.api.view.BounceHorizontalRecyclerView;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailScreenBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailScreenBean.DetailScreenShotInfo;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailScreenBean.DetailVideoInfo;
import com.huawei.appmarket.service.appdetail.view.GalleryActivityProtocol;
import com.huawei.appmarket.service.appdetail.view.GalleryActivityProtocol.Request;
import com.huawei.appmarket.support.video.VideoPlayer;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import o.cgz;
import o.chc;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cwv;
import o.dge;
import o.dgh;
import o.Logger;
import o.doo;
import o.ContentManager;
import o.dra;
import o.epv;
import o.CollectCheck;
import o.eqw;
import o.eqx;
import o.ActivityUtil;
import o.MinimumFactory;
import o.evn;
import o.evr;
import o.evt;
import o.ewm.d;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class DetailScreenGeneralCard extends BaseDistCard {
    private BounceHorizontalRecyclerView ʻ;
    private boolean ʻॱ = false;
    private boolean ʼ = false;
    private DetailScreenBean ʽ = null;
    private Map<Integer, DetailVideoInfo> ˊॱ = null;
    private int ˋ = ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(d.ˏॱ);
    private List<DetailVideoInfo> ˋॱ;
    private HashMap<ImageView, Integer> ˏॱ = new HashMap();
    private List<Boolean> ͺ;
    private boolean ॱˊ = true;
    private e ॱˋ;
    private int ॱˎ;
    private int ॱॱ;
    private ArrayList<String> ॱᐝ = new ArrayList();
    private int ᐝ;
    private int ᐝॱ;

    static class a extends s {
        private View ॱᐝ;
        private VideoPlayer ᐝॱ;

        private a(View view) {
            super(view);
            this.ᐝॱ = (VideoPlayer) view.findViewById(j.ᶥ);
            this.ॱᐝ = view.findViewById(j.ㆍ);
        }
    }

    class b extends androidx.recyclerview.widget.RecyclerView.a<s> implements OnClickListener {
        final /* synthetic */ DetailScreenGeneralCard ˊ;

        public b(DetailScreenGeneralCard detailScreenGeneralCard) {
            this.ˊ = detailScreenGeneralCard;
        }

        public s ˎ(ViewGroup viewGroup, int i) {
            return new a(LayoutInflater.from(this.ˊ.ʼॱ).inflate(h.ॱͺ, null));
        }

        public void ॱ(s sVar, int i) {
            if (sVar instanceof a) {
                String ˏ;
                int intValue;
                DetailVideoInfo detailVideoInfo = (DetailVideoInfo) this.ˊ.ˋॱ.get(i);
                a aVar = (a) sVar;
                if (this.ˊ.ॱˊ) {
                    ˏ = detailVideoInfo.ˏ();
                } else {
                    ˏ = null;
                }
                aVar.ᐝॱ.setVideoTag(detailVideoInfo.ˊ());
                aVar.ᐝॱ.setVideoBaseInfo(new o.evp.b().ˎ(detailVideoInfo.ᐝ()).ˊ(detailVideoInfo.ʽ()).ˋ(ˏ).ॱ(detailVideoInfo.ʼ()).ʼ(detailVideoInfo.ˋॱ()).ᐝ(detailVideoInfo.ͺ()).ʻ(evt.ˏ(detailVideoInfo.sp_)).ॱ());
                if (this.ˊ.ˊॱ == null) {
                    intValue = Integer.valueOf(i).intValue();
                } else {
                    intValue = Integer.valueOf(i).intValue() - this.ˊ.ˊॱ.size();
                }
                this.ˊ.ˏॱ.put(aVar.ᐝॱ.ॱॱ(), Integer.valueOf(intValue));
                if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                    this.ˊ.ˎ(aVar.ॱᐝ, i, ˏ(), detailVideoInfo.ˊॱ(), detailVideoInfo.ˏॱ());
                } else {
                    this.ˊ.ˏ(aVar.ॱᐝ, i, ˏ(), detailVideoInfo.ˊॱ(), detailVideoInfo.ˏॱ());
                }
                LayoutParams layoutParams = aVar.ᐝॱ.ॱॱ().getLayoutParams();
                layoutParams.width = detailVideoInfo.ˊॱ();
                layoutParams.height = detailVideoInfo.ˏॱ();
                aVar.ᐝॱ.ॱॱ().setOnClickListener(this);
                if (this.ˊ.ˊॱ == null || i >= this.ˊ.ˊॱ.size()) {
                    eqw.ˋ(aVar.ᐝॱ.ॱॱ(), detailVideoInfo.ʽ(), detailVideoInfo.ॱˊ(), "app_default_icon");
                } else {
                    eqx.ˏ(aVar.ᐝॱ.ॱॱ(), detailVideoInfo.ʽ(), "app_default_icon");
                }
            }
        }

        public int ˏ() {
            return this.ˊ.ˋॱ == null ? 0 : this.ˊ.ˋॱ.size();
        }

        public long ˏ(int i) {
            return (long) i;
        }

        public void onClick(View view) {
            if (view != null && (view instanceof ImageView) && this.ˊ.ॱˊ) {
                Context context = view.getContext();
                int intValue = ((Integer) this.ˊ.ˏॱ.get(view)).intValue();
                cjo galleryActivityProtocol = new GalleryActivityProtocol();
                Request request = new Request();
                request.ˊ(this.ˊ.ʼ);
                request.ˎ(intValue);
                request.ˋ(this.ˊ.ॱᐝ);
                request.ˋ(this.ˊ.ͺ);
                galleryActivityProtocol.ˎ(request);
                cjk.ˎ().ˋ(context, new cjm("gallery.activity", galleryActivityProtocol));
                dgh.onEvent(new dge.d(context, n.ˎˏ).ˏ(KeyAndValue.NUMBER_01).ˋ());
            }
        }
    }

    class e extends SafeBroadcastReceiver {
        private final Handler ˊ;
        private final Runnable ˋ;
        final /* synthetic */ DetailScreenGeneralCard ˏ;

        private e(DetailScreenGeneralCard detailScreenGeneralCard) {
            this.ˏ = detailScreenGeneralCard;
            this.ˊ = new Handler();
            this.ˋ = new Runnable(this) {
                final /* synthetic */ e ˋ;

                {
                    this.ˋ = r1;
                }

                public void run() {
                    evn ˎ = evr.ˊ().ˎ();
                    if (ˎ != null) {
                        ˎ.ʼ();
                    }
                }
            };
        }

        public void onReceiveMsg(Context context, Intent intent) {
            int ˊ = doo.ˊ(((ConnectivityManager) ContentManager.getInstant().getContext().getSystemService("connectivity")).getActiveNetworkInfo());
            if (ˊ != this.ˏ.ॱˎ) {
                this.ˏ.ॱˎ = ˊ;
                if (doo.ˊ(context)) {
                    this.ˊ.removeCallbacks(this.ˋ);
                    evn ˎ = evr.ˊ().ˎ();
                    if (ˎ != null) {
                        ˎ.ʼ();
                        return;
                    }
                    return;
                }
                this.ˊ.postDelayed(this.ˋ, 2000);
            }
        }
    }

    public /* synthetic */ cgz ˏ(View view) {
        return ॱ(view);
    }

    public DetailScreenGeneralCard(Context context) {
        super(context);
    }

    public DetailScreenGeneralCard ॱ(View view) {
        this.ʻ = (BounceHorizontalRecyclerView) view.findViewById(j.ˏ);
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        this.ʽ = (DetailScreenBean) cardBean;
        if (ˋ() && !ॱॱ()) {
            this.ʼ = ॱ(this.ʽ.ʽ());
            if (this.ʼ || this.ʻॱ) {
                this.ॱॱ = epv.ˎ(ContentManager.getInstant().getContext(), ˊ(), this.ˋ);
                this.ᐝ = (int) (((float) this.ॱॱ) * epv.ʼ());
            } else {
                this.ॱॱ = Math.round(ContentManager.getInstant().getContext().getResources().getDimension(d.ʼˋ));
                this.ᐝ = Math.round(ContentManager.getInstant().getContext().getResources().getDimension(d.ʻᐝ));
            }
            if (!CollectCheck.isEmpty(this.ʽ.ᶥ())) {
                this.ˊॱ = new LinkedHashMap();
                for (DetailVideoInfo detailVideoInfo : this.ʽ.ᶥ()) {
                    this.ˊॱ.put(Integer.valueOf(detailVideoInfo.ॱ()), detailVideoInfo);
                }
                this.ॱˎ = doo.ˊ(((ConnectivityManager) ContentManager.getInstant().getContext().getSystemService("connectivity")).getActiveNetworkInfo());
                if (this.ॱˋ == null) {
                    this.ॱˋ = new e();
                    ActivityUtil.registerReceiver(ContentManager.getInstant().getContext(), new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"), this.ॱˋ);
                }
            }
            ʼ();
            ˊॱ();
            cwv.ॱ().ˎ((String) this.ॱᐝ.get(0));
            cwv.ॱ().ˎ(this.ʼ);
        }
    }

    public static int ˊ() {
        return chc.ˊˋ();
    }

    public void ˎ() {
        ActivityUtil.unregisterReceiver(ContentManager.getInstant().getContext(), this.ॱˋ);
    }

    private boolean ˋ() {
        if (this.ʽ == null || this.ʽ.ˊ() == null || this.ʽ.ˊ().size() <= 0 || this.ʽ.ॱ() == null || this.ʽ.ॱ().size() <= 0) {
            return false;
        }
        return true;
    }

    private boolean ॱॱ() {
        String ˊ;
        boolean z = (this.ʽ.ꜞ() == null || this.ʽ.ꜞ().isEmpty()) ? false : true;
        this.ʻॱ = z;
        if (this.ʻॱ) {
            ˊ = ((DetailScreenShotInfo) this.ʽ.ꜞ().get(0)).ˊ();
            Logger.ˎ("DetailScreenCard", "Data contain screenShot");
            Object obj = ˊ;
        } else {
            String str = (String) this.ʽ.ˊ().get(0);
        }
        ˊ = (String) this.ʻ.getTag();
        if (!TextUtils.isEmpty(ˊ) && ˊ.equals(obj)) {
            return true;
        }
        this.ʻ.setTag(obj);
        return false;
    }

    private boolean ॱ(String str) {
        return DetailScreenBean.IMG_TAG_HORIZENTAL.equals(str);
    }

    private boolean ˊ(String str) {
        return "1".equals(str);
    }

    private void ʼ() {
        if (this.ˋॱ == null) {
            this.ˋॱ = new ArrayList();
        } else {
            this.ˋॱ.clear();
        }
        ʻ();
        ᐝ();
    }

    private void ʻ() {
        int size = this.ˊॱ == null ? 0 : this.ˊॱ.size();
        for (int i = 0; i < size; i++) {
            DetailVideoInfo detailVideoInfo = (DetailVideoInfo) this.ˊॱ.get(Integer.valueOf(i));
            if (detailVideoInfo != null) {
                detailVideoInfo.ˏ(detailVideoInfo.ˋ());
                detailVideoInfo.ॱ(this.ᐝ);
                if (!this.ʻॱ || this.ʼ) {
                    detailVideoInfo.ˎ(this.ॱॱ);
                } else {
                    detailVideoInfo.ˎ(Math.round(((float) this.ᐝ) * epv.ʼ()));
                }
                this.ˋॱ.add(detailVideoInfo);
            }
        }
    }

    private void ᐝ() {
        if (this.ʻॱ) {
            this.ॱᐝ.clear();
            if (this.ͺ == null) {
                this.ͺ = new ArrayList();
            } else {
                this.ͺ.clear();
            }
            for (DetailScreenShotInfo detailScreenShotInfo : this.ʽ.ꜞ()) {
                this.ॱᐝ.add(detailScreenShotInfo.ˊ());
                this.ͺ.add(Boolean.valueOf(ˊ(detailScreenShotInfo.ˏ())));
                DetailVideoInfo detailVideoInfo = new DetailVideoInfo();
                ॱ(detailVideoInfo, detailScreenShotInfo);
                this.ˋॱ.add(detailVideoInfo);
            }
            return;
        }
        this.ॱᐝ = this.ʽ.ˊ();
        int size = this.ʽ.ॱ() == null ? 0 : this.ʽ.ॱ().size();
        for (int i = 0; i < size; i++) {
            String str = (String) this.ʽ.ॱ().get(i);
            if (!(TextUtils.isEmpty(str) || ˎ(str))) {
                DetailVideoInfo detailVideoInfo2 = new DetailVideoInfo();
                detailVideoInfo2.ˏ(str);
                detailVideoInfo2.ˎ(this.ॱॱ);
                detailVideoInfo2.ॱ(this.ᐝ);
                detailVideoInfo2.ˋ(this.ʼ);
                this.ˋॱ.add(detailVideoInfo2);
            }
        }
    }

    private void ॱ(DetailVideoInfo detailVideoInfo, DetailScreenShotInfo detailScreenShotInfo) {
        String ॱ = detailScreenShotInfo.ॱ();
        if (ॱ != null) {
            String[] split = ॱ.split("\\*");
            if (split.length >= 2) {
                float floatValue;
                float floatValue2;
                boolean ˊ = ˊ(detailScreenShotInfo.ˏ());
                if (ˊ) {
                    floatValue = Float.valueOf(split[1]).floatValue();
                    floatValue2 = Float.valueOf(split[0]).floatValue();
                } else {
                    try {
                        floatValue = Float.valueOf(split[0]).floatValue();
                        floatValue2 = Float.valueOf(split[1]).floatValue();
                    } catch (NumberFormatException e) {
                        Logger.e("DetailScreenCard", "setScreenShotProperty parse resolution float value error");
                        return;
                    }
                }
                if (floatValue > 0.0f && floatValue2 > 0.0f) {
                    detailVideoInfo.ˎ(Math.round((floatValue / floatValue2) * ((float) this.ᐝ)));
                    detailVideoInfo.ॱ(this.ᐝ);
                    detailVideoInfo.ˏ(detailScreenShotInfo.ˋ());
                    detailVideoInfo.ˋ(ˊ);
                }
            }
        }
    }

    private void ˊॱ() {
        androidx.recyclerview.widget.RecyclerView.a bVar = new b(this);
        bVar.ˋ(true);
        RecyclerView.j linearLayoutManager = new LinearLayoutManager(this.ʻ.getContext(), 0, false);
        this.ʻ.setLayoutManager(linearLayoutManager);
        this.ʻ.setUnInterceptOnRight(true);
        if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            this.ʻ.setLayoutDirection(0);
            linearLayoutManager.ˊ(true);
        }
        this.ʻ.ॱ(new RecyclerView.n(this) {
            final /* synthetic */ DetailScreenGeneralCard ˎ;

            {
                this.ˎ = r1;
            }

            public void ˎ(RecyclerView recyclerView, int i) {
                this.ˎ.ᐝॱ = i;
                if (i == 0) {
                    evr.ˊ().ˎ(recyclerView);
                }
            }

            public void ˊ(RecyclerView recyclerView, int i, int i2) {
                evr.ˊ().ॱ(this.ˎ.ᐝॱ);
            }
        });
        this.ʻ.setAdapter(bVar);
        bVar.ˊ();
        evr.ˊ().ˋ(this.ʻ);
    }

    private boolean ˎ(String str) {
        for (DetailVideoInfo ʽ : this.ˋॱ) {
            if (str.equals(ʽ.ʽ())) {
                this.ॱᐝ.remove(str);
                return true;
            }
        }
        return false;
    }

    private void ˏ(View view, int i, int i2, int i3, int i4) {
        LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new LinearLayout.LayoutParams(i3, i4);
        }
        layoutParams.width = i3;
        layoutParams.height = i4;
        if (i == 0) {
            layoutParams.setMarginStart(dra.ˋ);
            layoutParams.setMarginEnd(0);
        } else if (i > 0 && i < i2) {
            layoutParams.setMarginStart(this.ˋ);
            layoutParams.setMarginEnd(0);
        }
        if (i == i2 - 1) {
            layoutParams.setMarginStart(this.ˋ);
            layoutParams.setMarginEnd(dra.ˋ);
        }
        view.setLayoutParams(layoutParams);
    }

    private void ˎ(View view, int i, int i2, int i3, int i4) {
        LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new LinearLayout.LayoutParams(i3, i4);
        }
        layoutParams.width = i3;
        layoutParams.height = i4;
        if (i == 0) {
            layoutParams.setMarginStart(0);
            layoutParams.setMarginEnd(dra.ˋ);
        } else if (i > 0 && i < i2) {
            layoutParams.setMarginStart(0);
            layoutParams.setMarginEnd(this.ˋ);
        }
        if (i == i2 - 1) {
            layoutParams.setMarginStart(dra.ˋ);
            layoutParams.setMarginEnd(this.ˋ);
        }
        view.setLayoutParams(layoutParams);
    }
}
